package com.qpf.spring.cloud.web.admin.controller;

import com.qpf.spring.cloud.commons.dto.BaseResult;
import com.qpf.spring.cloud.commons.utils.JsonUtils;
import com.qpf.spring.cloud.web.admin.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemoController {
    private DemoService demoService;
    @Autowired
    public DemoController(DemoService demoService) {
        this.demoService = demoService;
    }
    @GetMapping("demo")
    public String demo(@RequestParam(value = "message", required = false) String message) {
        return demoService.demo(message);
    }
    @GetMapping("users")
    public BaseResult users() {
        BaseResult result;
        try {
            result = JsonUtils.json2pojo(demoService.users(), BaseResult.class);
        } catch (Exception e) {
            result = BaseResult.ER(String.format("ERROR: %s", e.getMessage()));
        }
        return result;
    }
}
